package com.optimatch.model.db;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.TextField;

import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;

public class AutocompleteField extends JPanel {

	private static final long serialVersionUID = 1L;
	
	private TextField textField;
	private JList list;
	
	private Dico dico;
	
	public AutocompleteField() {
		super();
//		DB db = new DB();
//		dico = new Dico(db);
		this.textField = new TextField();
		AutocompleteFieldListModel model = new AutocompleteFieldListModel();
		this.list = new JList(model);
		textField.addKeyListener(new AutocompleteListener(model,this));
		textField.addTextListener(new AutocompleteListener(model,this));
		this.setLayout(new BorderLayout());
		this.add(textField,BorderLayout.PAGE_START);
		this.add(list,BorderLayout.CENTER);
	}
	
	public static void main(String[] args) {
		JFrame frame = new JFrame("Test auto-complete");
		frame.setPreferredSize(new Dimension(300,300));
		
		AutocompleteField text_field = new AutocompleteField();
		text_field.setDico(new Dico(new DB()));
		
		frame.getContentPane().add(text_field);
		
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		frame.pack();
		frame.setLocationRelativeTo(null);
		frame.setVisible(true);
	}

	public TextField getTextField() {
		return textField;
	}

	public JList getList() {
		return list;
	}
	
	public Dico getDico() {
		return dico;
	}
	
	public void setDico(Dico dico) {
		this.dico = dico;
	}
	
}
